#测试文件分类展示的页面，看是否从其他页面跳转过来
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from common.Utils import CloudDriver
from selenium.webdriver.support import expected_conditions as EC

class Display:
    url=""
    driver=""
    def __init__(self):
        self.url="http://vnollx.cloud/homepage"
        self.driver=CloudDriver.driver
        self.driver.get(self.url)

    def DispalyList(self):
        #点击到该页面
        self.driver.find_element(By.CSS_SELECTOR,"#categorylink").click()
        #根据该页面的元素查看是否跳转，需要上下文转换，因为页面是在iframe中的
        # 切换
        iframe = self.driver.find_element(By.TAG_NAME, "iframe")
        self.driver.switch_to.frame(iframe)
        #查找元素
        word=self.driver.find_element(By.CSS_SELECTOR,"body > div.category-buttons > div.button-group > button.category-btn.active").text
        assert word=="全部文件"

        #定位元素，右击选择
        elem=self.driver.find_element(By.CSS_SELECTOR,"#fileList > div:nth-child(1)")
        #定位
        EC.presence_of_element_located(elem)
        # 创建动作链对象
        actions = ActionChains(self.driver)
        # 右键点击元素
        actions.context_click(elem).perform()
        #查找预览
        self.driver.find_element(By.CSS_SELECTOR,"body > div.context-menu > div:nth-child(2)").click()
        #关闭
        self.driver.find_element(By.CSS_SELECTOR,"body > div.swal2-container.swal2-center.swal2-backdrop-show > div > button").click()

